package com.ldk.framework.service.impl;

import java.io.IOException;
import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ldk.base.framework.common.CustomException;
import com.ldk.base.framework.dao.IBaseDAO;
import com.ldk.base.framework.service.impl.BaseService;
import com.ldk.framework.service.IDictService;
import com.ldk.framework.service.IDictdataService;
import com.ldk.framework.dao.IDictDAO;
import com.ldk.framework.entity.Dict;
import com.ldk.framework.entity.Dictdata;

/**
* DictService接口实现类
* @author xiangwl
*/
@Service
public class DictService extends BaseService<Dict> implements IDictService {

	@Autowired
	private IDictDAO dictDAO;
	@Autowired
	private IDictdataService dictDataService;

	@Override
	protected IBaseDAO<Dict> getBaseDao() {
     	return this.dictDAO;
	}
	
	@Override
	@Transactional(rollbackFor={Exception.class, CustomException.class, NullPointerException.class, SQLException.class, IOException.class})
	public Boolean removeDict(String dbKey, int dictId) throws Exception {
		//删除数据字典值
		Dictdata dictData = new Dictdata();
		dictData.setDictId(dictId);
		dictDataService.delete(dbKey, dictData);
		
		//删除数据字典
		Dict query = new Dict();
		query.setDictId(dictId);
		
		deleteByKey("", query);
		
		return true;
	}
	
	@Override
	public Boolean getSystemAutoAssignTrip(String dbKey) {
		Dict query = new Dict();
		query.setDictId(5);//5为固定的系统自动指派行程的字典ID
		
		Dict dict = selectOne(dbKey, query);
		if(dict != null && dict.getEnabled())
			return true;
		return false;
	}
}
